using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;

namespace Pay.Service.AutoMapper {
	public class ShippingMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public ShippingMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {
			_cfg.CreateMap<shipping_dto, Shipping>()
				.ForMember(dest => dest.OrderId, src => src.MapFrom(c => c.order_id))
				.ForMember(dest => dest.ShipTo, src => src.MapFrom(c => c.ship_to))
				.ForMember(dest => dest.Phone, src => src.MapFrom(c => c.phone))
				.ForMember(dest => dest.RegionId, src => src.MapFrom(c => c.region_id))
				.ForMember(dest => dest.RegionName, src => src.MapFrom(c => c.region_name))
				.ForMember(dest => dest.Address, src => src.MapFrom(c => c.address))
				.ForMember(dest => dest.ExpressNo, src => src.MapFrom(c => c.express_no))
				.ForMember(dest => dest.ExpressCompanyName, src => src.MapFrom(c => c.express_company_name))
				.ForMember(dest => dest.ShipOrderNumber, src => src.MapFrom(c => c.ship_order_number))
				.ForMember(dest => dest.IdCard, src => src.MapFrom(c => c.id_card))
				.ForMember(dest => dest.RealName, src => src.MapFrom(c => c.real_name))
				.ForMember(dest => dest.CardNegative, src => src.MapFrom(c => c.card_negative))
				.ForMember(dest => dest.CardPositive, src => src.MapFrom(c => c.card_positive))
				.ForMember(dest => dest.ShippingTime, src => src.MapFrom(c => c.shipping_time.ToUnix()));
			_cfg.CreateMap<Shipping, shipping_dto>()
				.ForMember(dest => dest.order_id, src => src.MapFrom(c => c.OrderId))
				.ForMember(dest => dest.ship_to, src => src.MapFrom(c => c.ShipTo))
				.ForMember(dest => dest.phone, src => src.MapFrom(c => c.Phone))
				.ForMember(dest => dest.region_id, src => src.MapFrom(c => c.RegionId))
				.ForMember(dest => dest.region_name, src => src.MapFrom(c => c.RegionName))
				.ForMember(dest => dest.address, src => src.MapFrom(c => c.Address))
				.ForMember(dest => dest.express_no, src => src.MapFrom(c => c.ExpressNo))
				.ForMember(dest => dest.express_company_name, src => src.MapFrom(c => c.ExpressCompanyName))
				.ForMember(dest => dest.ship_order_number, src => src.MapFrom(c => c.ShipOrderNumber))
				.ForMember(dest => dest.id_card, src => src.MapFrom(c => c.IdCard))
				.ForMember(dest => dest.real_name, src => src.MapFrom(c => c.RealName))
				.ForMember(dest => dest.card_positive, src => src.MapFrom(c => c.CardPositive))
				.ForMember(dest => dest.card_negative, src => src.MapFrom(c => c.CardNegative))
				.ForMember(dest => dest.shipping_time, src => src.MapFrom(c => c.ShippingTime.ToDateTime()));
		}
	}
}
